<?php
/*
	首页
*/

defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
set_html('header','common/header-cms');
if($_RQ['op']=='main'){
	$return['list']=array();
	$return['indexpai']=array();
	$setting = plugin('jy_weishop')->plugin_setting('setting');
	if(!$setting['issearch']){
		$return['indexpai'][]=array('name'=>'search');
	}
	if(!$setting['ishdps']){
		$return['indexpai'][]=array('name'=>'hdps');
	}
	if(!$setting['iscube']){
		$return['indexpai'][]=array('name'=>'cube');
	}
	if(!$setting['isshare']){
		$return['indexpai'][]=array('name'=>'share');
	}
	if(!$setting['no_ordermodal']){
		$return['indexpai'][]=array('name'=>'ordermodal');
	}
	$return['indexpai'][]=array('name'=>'coupon');
	$return['indexpai'][]=array('name'=>'goods');
	$return['setting']=$setting;
	//推荐商品
	$parameter=array(
		'params'=>array('uniacid'=>$_SESSION['uniacid'],'saletype likes'=>array('1')),
		'fields'=>array('id','title','image','price','total','active_plugin','active_id','salenum','pluginname'),
		'limit'=>20,
	);
	$indexrecommands=model('jy_weishop/goods')->goods_list($parameter);
	$p_group=pdo_getall('jy_weishop_goods_group',array('uniacid'=>$_SESSION['uniacid'],'isshow'=>'1','parentid'=>'0'),'','paixu asc');
	//子分类
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1);
	$params['saletype likes']=array('1');
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','title','image','price','total','active_plugin','active_id');
	if($p_group){
		$i=0;
		foreach($p_group as &$item){
			$item['c_group']=pdo_getall('jy_weishop_goods_group',array('uniacid'=>$_SESSION['uniacid'],'isshow'=>'1','isrecommand'=>'1','parentid'=>$item['id']),'','paixu asc');
			$item['goodslist']=pdo_getslice('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'saletype likes'=>array('1'),'pcate'=>$item['id']),array($pindex,$psize),$total,$fields,'','paixu desc');
			$item['goodsnew']=pdo_getslice('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'saletype likes'=>array('2'),'pcate'=>$item['id']),array($pindex,$psize),$total,$fields,'','paixu desc');
			$item['style']=style($item['id']);
			$i=$i+1;
			$item['i']=$i;
			if($item['c_group']){
				foreach($item['c_group'] as &$row){
					$params['ccate']=$row['id'];
					$row['goods']=pdo_getslice('jy_weishop_goods',$params,array($pindex,$psize),$total,$fields,'','paixu desc');
				}
			}
		}
	}
	$parameter=array(
		//'table'=>'jy_weishop_goods',
		'fields'=>array('id','title','image','marketprice','price','total','salenum'),
		'orderby'=>'paixu desc',
		'limit'=>'5',
	);
	//
	$parameter['params']=array('saletype likes'=>array('1'),'uniacid'=>$_SESSION['uniacid'],'status'=>1);
	$recommand_list=model('jy_weishop/goods')->goods_list($parameter);
	//新品
	$parameter['params']=array('saletype likes'=>array('3'),'uniacid'=>$_SESSION['uniacid'],'status'=>1);
	$new_list=model('jy_weishop/goods')->goods_list($parameter);
	//热卖
	$parameter['params']=array('saletype likes'=>array('3'),'uniacid'=>$_SESSION['uniacid'],'status'=>1);
	$hot_list=model('jy_weishop/goods')->goods_list($parameter);
	//限时卖
	
	$time_list=model('jy_weishop/activity/limit')->goods_list(5);
	//促销
	
	$discount_list=model('jy_weishop/activity/sales')->goods_list(5);
	//公告列表
	$notice_list = pdo_fetchall('SELECT * FROM ' . tablename('jy_weishop_notice') . ' WHERE uniacid=:uniacid AND status=1  ORDER BY id DESC limit 4', array(':uniacid' => $_SESSION['uniacid']));
	if($notice_list){
		foreach($notice_list as &$notice){
			$notice['createtime']=date('Y-m-d h:i',$notice['createtime']);
		}
	}
	$pindex = max(1, intval($post['page']));
	$psize = 10;
	$total='';
	$return['orderlist']=pdo_getslice('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'deleted'=>0,'status'=>0),array($pindex,$psize),$total,'','','createtime desc');
	foreach($return['orderlist'] as &$ov){
		$ordergoods=pdo_get('jy_weishop_order_goods',array('orderid'=>$ov['id'],'uniacid'=>$_SESSION['uniacid']),array('goodsid','optionid','price','total','goodssn','productsn'));
		$goodsinfo=pdo_get('jy_weishop_goods',array('id'=>$ordergoods['goodsid'],'uniacid'=>$_SESSION['uniacid']),array('id','image','title','merchid'));
		$ov['goods']=array_merge($ordergoods,$goodsinfo);
		$ov['createtime']=date('Y/m/d H:i:s',$ov['createtime']);
		$ov['total']=pdo_getsum('jy_weishop_order_goods',array('orderid'=>$ov['id'],'uniacid'=>$_SESSION['uniacid']),'total');
	}
	$return['allprice']=pdo_getsum('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'deleted'=>0,'status'=>0),'price');
	//获取用户信息
	$return['indexrecommands']=$indexrecommands;
	$return['extradata']=array();
	$return['user']=model('core/member')->basic($_SESSION['uid']);
	$return['login']=$_SESSION['uid']?1:2;
	$return['recommand_list']=$recommand_list;
	$return['new_list']=$new_list;
	$return['hot_list']=$hot_list;
	$return['time_list']=$time_list;
	$return['discount_list']=$discount_list;
	$return['notice_list']=$notice_list;
	$return['p_group']=$p_group;
	$return['params']['pid']=0;
	set_html('title',$setting['title']?$setting['title']:'我的小店');
	$return['sharedata']=array(
		'title'=>$setting['share_title']?$setting['share_title']:'我的小店',
		'desc'=>$setting['share_desc']?$setting['share_desc']:'旺铺，一个属于自己的个人商城！',
		'link'=>custom_url('/weishop//fromuser='.$_SESSION['uid'],true),
		'imgUrl'=>ATTACHMENT_URL.$setting['share_image']
	);
	exi($return);
}
function style($id)
{
	switch ($id%7) {	
		case 0: return "style-brown";
		case 1: return 'style-red';
		case 2: return "style-pink";
		case 3: return "style-orange";
		case 4: return "style-green";
		case 5: return "style-blue";
		case 6: return "style-purple";
		case 7: return "style-brown";
		default: }
}
	
?>